using System;
using System.Collections.Generic;
using System.Text;
using GarageGames.Torque.T2D;
using Xyne.Objects.Common;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.Materials;
using Xyne.Utilities;
using GarageGames.Torque.Core;
using Microsoft.Xna.Framework;
using Xyne.Templates;
using Xyne.Templates.Card;

namespace Xyne.GUI.GUIControls.Menu
{
    public class MenuItem : T2DStaticSprite
    {
        #region Members
        private int menuID;

        public delegate void MenuItemSelectedDelegate(MenuItem menuItem);
        private MenuItemSelectedDelegate menuItemSelectedDelegate;

        private string menuText;

        private Vector2 defaultSize = new Vector2(100, 50);
        #endregion

        #region Properties
        public int MenuID
        {
            get
            {
                return menuID;
            }

            set
            {
                menuID = value;
            }
        }

        public MenuItemSelectedDelegate MenuItemSelected
        {
            get
            {
                return menuItemSelectedDelegate;
            }

            set
            {
                menuItemSelectedDelegate = value;
            }
        }

        public string MenuText
        {
            get
            {
                return menuText;
            }

            set
            {
                menuText = value;
            }
        }
        #endregion

        #region Constructor
        public MenuItem():
            this(int.MinValue)
        {
        }

        public MenuItem(int menuID)
        {

            this.menuID = menuID;
            Visible = false;
            Layer = Game.MenuItemLayer;
            menuItemSelectedDelegate = null;
            Size = defaultSize;
            Material = new SimpleMaterial();
        }

        public MenuItem(string menuText):
            this(int.MinValue)
        {
            this.menuText = menuText;
        }
        #endregion

        #region Methods
        public virtual void Selected()
        {
            if (menuItemSelectedDelegate != null)
            {
                menuItemSelectedDelegate(this);
            }
        }

        public virtual void RefreshTexture()
        {
            Texture2D menuItemTexture = Card.StandardBackgroundTexture;
            XyneText myText = new XyneText();
            myText.Color = Color.Black;
            myText.Position = new Vector2(10, 10);
            myText.Text = menuText;
            myText.Font = ResourceManager.Instance.LoadFont("Arial16");

            (Material as SimpleMaterial).SetTexture(MaterialHelper.DrawTextOnTexture(menuItemTexture, myText, defaultSize));
        }
        #endregion
    }
}
